﻿@inherits LayoutComponentBase
@inject NavigationManager NavigationManager
@inject ISettingService _settingService

<AuthorizeView>
    <Authorized>
        @if (_settingService.IsApp)
        {
            <MAppBar App Style="background-color: var(--md-sys-color-background)!important;" Dense>
             <MAppBarNavIcon @onclick="@(()=>SetDrawer())"></MAppBarNavIcon>

             <CnGalWebSite.GameSite.Shared.Components.Layout.TitleCard />
                <MSpacer></MSpacer>

                <MButton Icon OnClick="OnClickSearch">
                    <MIcon>mdi-magnify</MIcon>
                </MButton>
            </MAppBar>
            <CnGalWebSite.GameSite.Shared.Components.Admin.NavMenu @ref="navButton" OnRefresh="OnRefreshLayout" />

        }
        <MMain>

            <CascadingValue Value="this" IsFixed="true">
                @if (_settingService.IsApp == false)
                    {
                        <CnGalWebSite.Components.Cards.MDCard Style=" min-height: 100vh; top: 0px; max-height: calc(100% - 0px);width: 300px; position: fixed; min-width: 300px;" Class="me-4">
                            <div style="display: flex; justify-content: center; " class="mt-6 mb-6">
                            <CnGalWebSite.GameSite.Shared.Components.Layout.LogoCard />
                            </div>
                        <CnGalWebSite.GameSite.Shared.Components.Admin.LeftMenu Style="overflow-y: auto; height: calc(100vh - 85px);background-color:transparent" Class="scroll" />
                        </CnGalWebSite.Components.Cards.MDCard>
                        <div style=" margin-left: 317px; margin-bottom: 17px;">
                            <div style=" position: fixed; right: 0; z-index: 3; left: 317px;top:0">
                            <CnGalWebSite.GameSite.Shared.Components.Admin.TopBar />
                            </div>
                            <div style="margin-top: 85px;" class="me-4">
                            <ErrorHandler ShowDetailedErrorInfor>
                                    @Body
                                </ErrorHandler>

                            </div>
                        </div>
                    }
                    else
                    {
                        <CnGalWebSite.Components.Containers.MasaContainer>
                        <ErrorHandler ShowDetailedErrorInfor>
                                @Body
                            </ErrorHandler>
                        </CnGalWebSite.Components.Containers.MasaContainer>
                    }
            </CascadingValue>
        </MMain>
    </Authorized>
    <NotAuthorized>
        <CnGalWebSite.Components.Containers.MasaContainer>
            <NotFoundCard Page/>
        </CnGalWebSite.Components.Containers.MasaContainer>
    </NotAuthorized>
</AuthorizeView>

<CnGalWebSite.Components.Verifications.SynchronousAuthStateCard />
@code {
    CnGalWebSite.GameSite.Shared.Components.Admin.NavMenu navButton;

    public void OnClickSearch()
    {
        NavigationManager.NavigateTo("/search");
    }

    public void SetDrawer()
    {
        if (navButton != null)
        {
            navButton.SetDrawer(true);
        }
    }

    public void OnRefreshLayout()
    {
        NavigationManager.NavigateTo("/");
    }
}
